
var _path = '/zpmng/';
//url:form add and edit jsp
var _formAddEditUrl="/admin123/coding/owrDoubleTaskPair/add_edit_building.jsp";
//url:form add action
var _formAddAction="/admin123/coding/owrDoubleTaskPair/owrDoubleTaskPairAjax_addData.action";
//url:form edit action
var _formEditAction="/admin123/coding/owrDoubleTaskPair/owrDoubleTaskPairAjax_editData.action";
//url:form remove action
var _formRemoveAction="/admin123/coding/owrDoubleTaskPair/owrDoubleTaskPairAjax_removeData.action";
//url:report
var _formReportAction="/admin123/coding/owrDoubleTaskPair/add_edit_building.jsp";
//url:reportPDF
var _formReportPDFAction = "/admin123/coding/owrDoubleTaskPair/owrDoubleTaskPairAjax_downloadBatch.action";
//url:form createTaskList jsp
var _formCreateTaskListUrl = "/admin123/coding/owrDoubleTaskPair/create_taskList_building.jsp";
//url:form sendToTask jsp
var _formSendToTaskUrl = "/admin123/coding/owrDoubleTaskPair/send_to_task_building.jsp";
//url:form CreateTaskListBuilding action
var _formCreateTaskListBuildingAction = "/admin123/coding/owrDoubleTaskPair/owrDoubleTaskPairAjax_createTaskListBuilding.action";
//url:form SendToTaskBuilding action
var _formSendToTaskAction = "/admin123/coding/owrDoubleTaskPair/owrDoubleTaskPairAjax_sendToTask.action";






var _keyRandom='owr_double_task_pair';
//上个页面通过右击列表 传过来的 id和row; ps:右击模板x列，看模板列列表，自动加载列数，要传模板id找表名
var _prePageListRow = '${paramValues.row[0]}';
_prePageListRow = decodeURI(_prePageListRow);
var _prePageListId = '${paramValues._id[0]}';

//template table foreign key
var _foreignKey = '';
var _primaryKey = 'id';

//add dialog width and height
var _width4AddDialog = '0';
var _height4AddDialog = '0';
if(_width4AddDialog == '' || _width4AddDialog == '0')_width4AddDialog=800;
if(_height4AddDialog == '' || _height4AddDialog == '0')_height4AddDialog=400;
//dialog style, 取代上面的方法
var _isdialog4AddDialog = '1';
var _style4AddDialog = 'width:800px;height:400px;';
if(_style4AddDialog == '')_style4AddDialog='width:800px;height:400px';


/*
	hidden fileds when option has changed
	选择optionId时，filedList是要隐藏的域
	结构如下 ：
	var hiddenFileds = [
		{"optionId":"11","filedList":[{"text":"foreignkey"},{"text":"tablenamesql"}]},
		{"optionId":"12","filedList":[{"text":"tablenamehistorysql"},{"text":"sqlsum"}]}
	];
*/
var hiddenFileds = []



/**
	页面datagrid控件显示列元素：datagrid.columns
*/
// var datagrid_columns = [[{"field":"id","width":100,"title":"ID"},{"field":"deleteflag","width":100,"title":"deleteflag"},{"field":"createdate","width":100,"title":"createdate"},{"field":"createman","width":100,"title":"createman"},{"field":"modifydate","width":100,"title":"modifydate"},{"field":"modifyman","width":100,"title":"modifyman"},{"field":"createmanId","width":100,"title":"createman_id"},{"field":"modifymanId","width":100,"title":"modifyman_id"},{"field":"companyId","width":100,"title":"company_id"},{"field":"owrRegionId","width":100,"title":"owr_region_id"},{"field":"regionName","width":100,"title":"region_name"},{"field":"quarter","width":100,"title":"quarter"},{"field":"userId","width":100,"title":"检查人员"},{"field":"entityId","width":100,"title":"受检餐厨企业"},{"formatter":function(value,rowData,rowIndex){if(typeof(rowData.id) == 'undefined'){return '';};var btn = '';btn += '<a linetail=\"edit\" class=\"editcls\" style=\"height:20px;\" onclick=\"editRow('+rowIndex+')\" href=\"javascript:void(0)\">编辑<\/a>';btn += '<a linetail=\"del\" class=\"delcls\" style=\"height:20px;\" onclick=\"removeRow('+rowIndex+')\" href=\"javascript:void(0)\">删除<\/a>'; return btn;},"field":"opt","width":160,"title":"操作","align":"center"}]]
var datagrid_columns = [[
	/*{
		"formatter": function (value, rowData, rowIndex) {
			if (typeof (rowData.id) == 'undefined') {
				return '';
			}
			;var btn = '';
			btn += '<a linetail=\"report\" class=\"savecls\" style=\"height:20px;\" onclick=\"downloadReport4doubleRandom(' + rowIndex + ')\" href=\"javascript:void(0)\">下载<\/a>';
			//btn += '<a linetail=\"edit\" class=\"editcls\" style=\"height:20px;\" onclick=\"editRow(' + rowIndex + ')\" href=\"javascript:void(0)\">详细<\/a>';
			return btn;
		}, "field": "opt", "width": 70, "title": "操作", "align": "center"
	},*/
	{
		"formatter": function (value, rowData, rowIndex) {
			if (typeof (rowData.id) == 'undefined') {
				return '';
			};
			var btn = '';
			if(rowData.owTaskId==0){
				btn += '<a linetail=\"edit\" class=\"editcls\" style=\"height:20px;\" ' +
					'onclick=\"editRow(' + rowIndex + ')\" href=\"javascript:void(0)\">编辑<\/a>'
				;
			}
			return btn;
		},
		"field": "opt", "width": 80, "title": "操作", "align": "center"
	},
	{"field": "id", "hidden": "true","width": 100, "title": "ID"},
	{"field": "userName", "width": 150, "title": "检查人员"},
	{"field": "entityName", "width": 300, "title": "受检工地企业"},
	{"field": "regionName", "width": 150, "title": "所属区域"},
	{"field": "year", "width": 100, "title": "抽查年份"},
	{"field": "month", "width": 100, "title": "抽查月份"},
	{"field": "owrTypeName", "width": 100, "title": "分类"},
	{"field": "owTaskId_Str", "width": 100, "title": "派发状态"},
	{"field": "owTaskStatus_Str", "width": 100, "title": "任务处理状态"},
	{"field": "improveRequied", "width": 100, "title": "检查内容"},
	{"field": "dealIssueContent", "width": 100, "title": "存在问题"},
	{"field": "dealResult", "width": 100, "title": "处理意见"},
	{"field": "dealTime", "width": 100, "title": "处理时间"},
	{"field": "owrType", "width": 100, "title": "分类", "hidden": true},
	{"field": "userId", "hidden": "true","width": 100, "title": "检查人员"},
	{"field": "entityId","hidden": "true", "width": 100, "title": "受检餐厨企业"},
	{"field": "createmanId", "width": 100, "title": "createman_id", "hidden": true},
	{"field": "modifymanId", "width": 100, "title": "modifyman_id", "hidden": true},
	{"field": "companyId", "width": 100, "title": "company_id", "hidden": true},
	{"field": "createdate", "width": 130, "title": "创建日期"},
	{"field": "createman", "width": 100, "title": "创建人"},
	{"field": "modifydate", "width": 100, "title": "修改日期", "hidden": true},
	{"field": "modifyman", "width": 100, "title": "修改人", "hidden": true}
	]]


/**
页面datagrid控件显示列元素：datagrid.frozenColumns
*/
var datagrid_frozenColumns = []
var jarrTmp = [];
var jo = {
"formatter":function(value,rowData,rowIndex){
if(typeof(rowData.id) == 'undefined'){return '';};
var btn = '';
btn += '<a rowIndex=\"'+rowIndex+'\" class=\"button\" style=\"height:16px;\"  href=\"javascript:void(0)\">菜单<\/a>';
    return btn;
    },
    "field":"menuItem",
    "width":70,
    "title":"菜单列表",
    "align":"center",
    "hidden":false};
var jarr = [];
jarr.push(jo);
$.each(jarrTmp,function(index,value){
jarr.push(jarrTmp[index]);
})
datagrid_frozenColumns.push(jarr);


    /**
页面datagrid控件显示列元素：datagrid.toolbarBtns
*/
var datagrid_toolbarBtns = [];
/*datagrid_toolbarBtns[datagrid_toolbarBtns.length] = {
 id:'toolbarAddBtnId',text:'添加',
 iconCls:'icon-add',
 handler:function(){toolbar_add();}
}*/
datagrid_toolbarBtns[datagrid_toolbarBtns.length] = {
	id:'toolbarAddBtnId',text:'生成任务清单',
	iconCls:'icon-edit',
	handler:function(){toolbar_createTaskList();}
}

datagrid_toolbarBtns[datagrid_toolbarBtns.length] = {
	id: 'toolbarReportBtnId', text: '派发任务',
	iconCls: 'icon-add',
	handler: function () {
		toolbar_sendToTask();
	}
}
/*已处理双随机任务报表下载*/
datagrid_toolbarBtns[datagrid_toolbarBtns.length] = {
	id: 'toolbarReportBtnId', text: '报表下载',
	iconCls: 'icon-save',
	handler: function () {
		downloadReportV2();
	}
}


function downloadReportV2() {
	//定义一个form表单
	var myform = $("<form></form>");
	myform.attr('method', 'post')
	myform.attr('action', _path + _formReportPDFAction);

	var owTaskStatus = $("<input type='hidden' name='owTaskStatus' />")
	var owTaskStatusValue = $("#owTaskStatus").combobox("getValue");
	if (owTaskStatusValue != "") {
		owTaskStatus.attr('value', owTaskStatusValue);
		myform.append(owTaskStatus);
	}

	var owrRegionId = $("<input type='hidden' name='owrRegionId' />")
	var owrRegionIdValue = $("#owrRegionId").combobox("getValue");
	if (owrRegionIdValue != "") {
		owrRegionId.attr('value', owrRegionIdValue);
		myform.append(owrRegionId);
	}


	var year = $("<input type='hidden' name='year' />")
	var yearValue = $("#year").combobox("getValue");
	if (yearValue != "") {
		year.attr('value', yearValue);
		myform.append(year);
	}

	var month = $("<input type='hidden' name='month' />")
	var monthValue = $("#month").combobox("getValue");
	if (monthValue != "") {
		month.attr('value', monthValue);
		myform.append(month);
	}

	var owrType = $("<input type='hidden' name='owrType' />")
	var owrTypeValue = $("#owrType").textbox("getValue");
	if (owrTypeValue != "") {
		owrType.attr('value', owrTypeValue);
		myform.append(owrType);
	}

	myform.appendTo('body').submit();
};



/**
datagrid ，后面在condition.js中init了
*/
var datagrid={
	datagridId:"list",
	datagridUrl:"owrDoubleTaskPairAjax_queryListBySearch.action",
	datagridObj:{
		/*title:"查询列表",*/
		nowrap:true,
		autoRowHeight:false,
		fit:true,
		columns:datagrid_columns,//datasoure in data.js
		frozenColumns:datagrid_frozenColumns,
		toolbar:datagrid_toolbarBtns,
		rownumbers:true,
		showFooter:true,
		onRowContextMenu:onRowContextMenu
	}
};


var isFirstLoadSuccess = true;
datagrid.datagridObj.onLoadSuccess=function(){
	$('#'+datagrid.datagridId).datagrid('loaded');
	$("#queryBtn_Filter").removeAttr("disabled");
	$('.editcls').linkbutton({plain:true,iconCls:'icon-edit'});  //给每行后的button加easyui样式
	$('.savecls').linkbutton({plain:true,iconCls:'icon-save'});
	//行尾button显示或隐藏
	$("[linetail='edit']").hide();
	authRequestUrl(_formEditAction,function(authResult){
		if(authResult){
			$("[linetail='edit']").show();
		}
	});
	$("[linetail='del']").hide();
	authRequestUrl(_formRemoveAction,function(authResult){
		if(authResult){
			$("[linetail='del']").show();
		}
	});

	//根据防问权限控制toolbar button显示或隐藏
	if (isFirstLoadSuccess) {
	$('#toolbarAddBtnId').hide();
	authRequestUrl(_formAddAction,function(authResult){
	 if(authResult){
	     $('#toolbarAddBtnId').show();
	  }
	});
	isFirstLoadSuccess = false;
	}


	//行首菜单button,打开菜单列表
	$.each($("a"),function(index,value){
		var obj = $(this);
		var rowIndex1 = obj.attr("rowIndex");
		if(rowIndex1 != undefined){
			obj.mouseover(function(e){
				var obj = $(this);
				var offset = obj.offset();
				e.preventDefault();
				rowIndex = rowIndex1;
				var selected=$("#list").datagrid('getRows'); //获取所有行集合对象
				if(selected[rowIndex] == null){return;}
				id = selected[rowIndex].id; //index为当前右键行的索引，指向当前行对象
				$('#rightMenuDiv').menu('show', {
					left:offset.left+47,
					top:offset.top-5
				});
			});
		}
	});
};



//添加右击菜单内容
var id;
var rowIndex;
function onRowContextMenu(e, rowIndex1, rowData){
	e.preventDefault();
	rowIndex = rowIndex1;
	var selected=$("#list").datagrid('getRows'); //获取所有行集合对象
	if(selected[rowIndex] == null){return;}
	id = selected[rowIndex].id; //index为当前右键行的索引，指向当前行对象
	$('#rightMenuDiv').menu('show', {
		left:e.pageX,
		top:e.pageY
	});
};




/**
打开AddDialog时，加载默认值
*/
var _defaultValueJOStr = {}


/**
所有列备份一下，一会隐藏了，可以恢复
*/
var _columnDivArray = new Array();
_columnDivArray[_columnDivArray.length] = '#_owr_region_id_line';
_columnDivArray[_columnDivArray.length] = '#_region_name_line';
_columnDivArray[_columnDivArray.length] = '#_quarter_line';
_columnDivArray[_columnDivArray.length] = '#_user_id_line';
_columnDivArray[_columnDivArray.length] = '#_entity_id_line';


